package homework;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

public class RiceFilter {

    public List<Rice> filter(List<Rice> riceList, Predicate<Rice> predicate) {
        List<Rice> filteredList = new ArrayList<>();
        for (Rice rice : riceList) {
            if (predicate.test(rice)) {  // 满足条件的元素加入结果集
                filteredList.add(rice);
            }
        }
        return filteredList;
    }


    public <T> List<T> map(List<Rice> riceList, Function<Rice, T> function) {
        List<T> mappedList = new ArrayList<>();
        for (Rice rice : riceList) {
            mappedList.add(function.apply(rice));  // 应用转换规则
        }
        return mappedList;
    }
}
